package cn.itcast.oa.view.action;

import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import cn.itcast.oa.base.BaseAction;
import cn.itcast.oa.domain.Forum;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ModelDriven;

@Controller
@Scope("prototype")
public class ForumManageAction extends BaseAction<Forum> implements ModelDriven<Forum>{

	
	private static final long serialVersionUID = 1L;

	/**列表*/
	public String list(){
		List<Forum> forumList = forumService.findAll();
		ActionContext.getContext().put("forumList", forumList);
		return "list";
	}
	
	/**删除*/
	public String delete(){
		forumService.delete(model.getId());
		return "tolist";
	}
	
	/**添加页面*/
	public String addUI(){
		
		return "saveUI";
	}
	
	/**添加*/
	public String add(){
		//model.setName(model.getName());
		//model.setDescription(model.getDescription());
		
		forumService.save(model);
		return "tolist";
	}
	
	/**修改页面*/
	public String editUI(){
		Forum forum = forumService.getById(model.getId());
		ActionContext.getContext().getValueStack().push(forum);
		return "saveUI";
	}
	
	/**修改*/
	public String edit(){
		Forum forum = forumService.getById(model.getId());
		//forum.setName(model.getName());
		//forum.setDescription(model.getDescription());
		forumService.update(forum);
		return "tolist";
	}
	
	/** 上移 */
	public String moveUp() {
		forumService.moveUp(model.getId());
		return "tolist";
	}

	/** 下移 */
	public String moveDown() {
		forumService.moveDown(model.getId());
		return "tolist";
	}

}
